#include "MatView.hpp"


MatView::MatView(void)
{
}


MatView::~MatView(void)
{
}

void	MatView::translate(float x, float y, float z)
{
	Vec3f	tra(x, y, z);

	translation(tra);
}

void	MatView::rotate(float angle, float x, float y, float z)
{
	Vec3f	rot(x, y, z);

	rotation(angle, rot);
}

Mat3f	MatView::normalMat() const
{
	Mat3f	normalMat;
	int		x, y;

	for (y = 0; y < 3; y++)
		for (x = 0; x < 3; x++)
			normalMat(y, x) = (*this)(y, x);
	return normalMat;
}

void	MatView::lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float axeX, float axeY, float axeZ)
{
	static 	Mat4f	t;

	_eye = Vec3f(eyeX, eyeY, eyeZ);
	_center = Vec3f(centerX, centerY, centerZ);
	_axe = Vec3f(axeX, axeY, axeZ);

	_visionVec = _center - _eye;
	_normalVec = _axe.prodVec(_visionVec);
	_newAxeVec = _visionVec.prodVec(_normalVec);

	_visionVec.normalize();
	_normalVec.normalize();
	_newAxeVec.normalize();

	t.loadIdentity();

	t(0, 0) = _normalVec[0];
	t(0, 1) = _normalVec[1];
	t(0, 2) = _normalVec[2];

	t(1, 0) = _newAxeVec[0];
	t(1, 1) = _newAxeVec[1];
	t(1, 2) = _newAxeVec[2];

	t(2, 0) = -_visionVec[0];
	t(2, 1) = -_visionVec[1];
	t(2, 2) = -_visionVec[2];

	*this *= t;
	this->translate(-_eye[0], -_eye[1], -_eye[2]);
}
